import { getUserInfoUrl } from "@/command/apiTool";
import { useDetail } from "@/hooks";
import { useRoute } from "vue-router";
import { getAction } from "@/command/netTool";
import * as vant from "vant";
const { showFailToast, showSuccessToast } = vant;
export const useRequest = () => {
  const route = useRoute();
  const [detail, detailControl] = useDetail(
    getUserInfoUrl(
      {
        dh: "/api/H5/richHelpGuaranteedSupplyTask/large/getOne",
        xh: "/api/H5/richHelpGuaranteedSupplyTask/small/getOne",
      },
      { taskId: route.query.id || "" }
    ),
    {
      id: "",
      title: "",
      content: "",
      createDate: "",
      partakeFlag: "",
      richHelpGuaranteedSupplyTaskPartakes: [],
    }
  );

  const btnAction = (url: any, params: any) => {
    getAction(url, { ...params }, { isResolve: true }).then((e) => {
      console.log("eee", e);
      showSuccessToast(e.msg);
      // 刷新接口
      detailControl.refresh();
    });
  };

  const accept = (id: any, status: any, userIds?: any) => {
    let Url = {
      dh: "/api/H5/richHelpGuaranteedSupplyTask/large/accept",
      xh: "/api/H5/richHelpGuaranteedSupplyTask/small/acceptOrRefuse",
    };
    const action = getUserInfoUrl(Url, {
      taskId: id,
      status: status,
      userIds: userIds,
    });
    btnAction(action.url, action.params);
  };

  const refuse = (id: any, status: any) => {
    let Url = {
      dh: "/api/H5/richHelpGuaranteedSupplyTask/large/refuse",
      xh: "/api/H5/richHelpGuaranteedSupplyTask/small/acceptOrRefuse",
    };
    const action = getUserInfoUrl(Url, { taskId: id, status: status });
    btnAction(action.url, action.params);
  };

  // 结队小户列表
  const [memberList] = useDetail(
    getUserInfoUrl({
      dh: "/api/H5/richCourse/large/getMemberList",
      xh: "",
    }),
    []
  );

  return {
    detail,
    accept,
    refuse,
    memberList,
  };
};
